﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using System.Data;
using DTO;

namespace DAO
{
    public class TonGiaoDAO
    {
        public static List<TonGiaoDTO> LayDanhSach()
        {
            List<TonGiaoDTO> lstTonGiao = new List<TonGiaoDTO>();
            OleDbConnection cnn = BoKetNoiCSDL.TaoKetNoi();
            string query = "select * from Ton_Giao";
            OleDbCommand cmd = new OleDbCommand(query, cnn);
            cnn.Open();
            try
            {
                OleDbDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    TonGiaoDTO TonGiaoDto = new TonGiaoDTO();
                    TonGiaoDto.MaTonGiao = (int)dr["TonGiaoID"];
                    TonGiaoDto.TenTonGiao = (string)dr["TenTonGiao"];
                    lstTonGiao.Add(TonGiaoDto);
                }
            }
            catch
            {
                if (cnn.State == ConnectionState.Open)
                    cnn.Close();
                throw new Exception("thao tác lấy danh sách tôn giáo bị lỗi");
            }
            finally
            {
                cnn.Dispose();
            }
            return lstTonGiao;
        }
    }
}
